package yz.cp.back.common.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

public class I18nService {

    private final MessageSource messageSource;

    public I18nService(MessageSource messageSource) {
        this.messageSource = messageSource;
    }

    public String getMessage(String msgKey, Object[] args) {
        return messageSource.getMessage(msgKey, args, LocaleContextHolder.getLocale());
    }

    public String getMessage(String msgKey) {
        return messageSource.getMessage(msgKey, null,LocaleContextHolder.getLocale());
    }
    public String getMessage(String msgKey,String defaultStr) {
        String a=messageSource.getMessage(msgKey, null,LocaleContextHolder.getLocale());
        if(StringUtils.isBlank(a)){
            return defaultStr;
        }else {
            return a;
        }
    }
}
